home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / misc_pto / linktext / linktext.doc next >
Text File  |  1989-03-20  |  1KB  |  21 lines

  1. Writing your own editor?  These Turbo Pascal routines may get you started.
  2.  
  3. When handling text files in Turbo Pascal, it is convinient to read the file
  4. into an array of strings.  While this may be fine for some applications,
  5. the array size is limited by the 64K data segment that must be shared with
  6. other variables.  Another way to buffer text is to allocate memory
  7. dynamically from the heap using GetMem.
  8.  
  9. My sample program LinkText.PAS demonstrates how to read a text file into a
  10. singly linked list.  Each element in the list contains a string and a
  11. pointer to the next element.  The "Head" record is actually a dummy element,
  12. which contains only a pointer field that always points to the first real
  13. element in the list.  Notice that we must allocate 5 bytes more than the
  14. length of the string.  This allows for the length byte of the string and
  15. the 4 bytes required for the pointer field.
  16.  
  17. The procedure DisplayFile traverses the list from top to bottom and writes
  18. each line of the list.  The DeleteLine and InsertLine procedures show how
  19. to insert and delete records from this type of list by changing pointers.
  20.  
  21. --- Michael A. Reeder; Beaumont, Texas